/*
 *
 *      Copyright (c) 2018-2025, scs All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: scs
 *
 */

package com.zyh.scs.admin.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyh.scs.admin.api.dto.UserDTO;
import com.zyh.scs.admin.api.dto.UserPageDTO;
import com.zyh.scs.admin.api.entity.SysUser;
import com.zyh.scs.admin.api.vo.UserVO;
import com.zyh.scs.common.data.datascope.DataScope;
import com.zyh.scs.common.data.datascope.ScsBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author scs
 * @since 2017-10-29
 */
@Mapper
public interface SysUserMapper extends ScsBaseMapper<SysUser> {

    /**
     * 通过用户名查询用户信息（含有角色信息）
     *
     * @param username 用户名
     * @return userVo
     */
    UserVO getUserVoByUsername(String username);

    /**
     * 分页查询用户信息
     *
     * @param page        分页
     * @param userPageDTO 查询参数
     * @param dataScope
     * @return list
     */
    IPage<UserVO> getUserVosPage(Page page, @Param("query") UserPageDTO userPageDTO, DataScope dataScope);

    /**
     * 通过ID查询用户信息
     *
     * @param id 用户ID
     * @return userVo
     */
    UserVO getUserVoById(Long id);

    /**
     * 查询用户列表
     *
     * @param userDTO   查询条件
     * @param dataScope 数据权限声明
     * @return
     */
    List<UserVO> selectVoListByScope(@Param("query") UserDTO userDTO, @Param("ids") Long[] ids, DataScope dataScope);

    /**
     * 查询现金账户金额元总和
     *
     * @return
     */
    BigDecimal selectAllCashAmount();

    /**
     * 查询餐补账户账户金额元总和
     *
     * @return
     */
    BigDecimal selectAllCardAmount();

    /**
     * 查询出账户用户类型
     *
     * @param userPageDTO
     * @return
     */
    List<SysUser> getUserTypeNumber(@Param("query") UserPageDTO userPageDTO);

    SysUser selectByGuid(@Param("guid") String guid);

    void incrByCardAccount(@Param("guid") String guid, @Param("rechargeNumber") BigDecimal rechargeNumber, @Param("updateTime") LocalDateTime updateTime);

    void incrByCashAccount(@Param("guid") String guid, @Param("rechargeNumber") BigDecimal rechargeNumber, @Param("updateTime") LocalDateTime updateTime);

    void deductionIncrByCardAccount(@Param("guid") String guid, @Param("deductionMoney") BigDecimal deductionMoney, @Param("updateTime") LocalDateTime updateTime);

    void deductionIncrByCashAccount(@Param("guid") String guid, @Param("deductionMoney") BigDecimal deductionMoney, @Param("updateTime") LocalDateTime updateTime);


    void updateByGuid(@Param("guid") String guid, @Param("password") String password);
}
